<!--
 * @Description:厂端车主查询明细页
 * @Autor: 刘诗文
 * @Date: 2021-01-08 15:48:22
 * @LastEditors: 马毅
 * @LastEditTime: 2021-06-09 13:57:11
-->
<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :cols="3" :labelWidth="130" :formType="type" :isSubmitBtn="false" />
    <div style="margin-bottom: 1rem;"></div>
    <el-tabs v-model="activeTab">
      <el-tab-pane label="车辆信息" :name="'vehicleInfo'">
        <FilterTable
          ref="vehicleInfo"
          columnsRef="vehicleInfolsw"
          height="300"
          :isSelectColumn="false"
          :dataSource="vehicleInfoList"
          :fetchapi="vehicleInfoFetchapi"
          :params="vehicleInfoFetchParams"
          :onSyncTableData="handleSyncTableDataVehicle"
          :columns="vehicleInfoColumns"
          :datakey="'rows'"
          :onColumnsChange="columns => (this.vehicleInfoColumns = columns)"
          v-if="activeTab == 'vehicleInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <!--      <el-tab-pane label="介绍人信息" :name="'introducerInfo'">-->
      <!--        <FilterTable-->
      <!--          ref="introducerInfo"-->
      <!--          columnsRef="introducerInfolsw"-->
      <!--          height="300"-->
      <!--          :isSelectColumn="false"-->
      <!--          :dataSource="introducerInfoList"-->
      <!--          :columns="introducerInfoColumns"-->
      <!--          :onColumnsChange="columns => (this.introducerInfoColumns = columns)"-->
      <!--        >-->
      <!--        </FilterTable>-->
      <!--      </el-tab-pane>-->
      <el-tab-pane label="线索信息" :name="'clueInfo'">
        <FilterTable
          ref="clueInfo"
          columnsRef="clueInfolsw"
          height="300"
          :isSelectColumn="false"
          :dataSource="clueInfoList"
          :params="clueParams"
          :fetchapi="clueApi"
          :datakey="'records'"
          :onSyncTableData="handleSyncTableDataClueInfo"
          :columns="clueInfoColumns"
          :onColumnsChange="columns => (this.clueInfoColumns = columns)"
          v-if="activeTab == 'clueInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="销售订单信息" :name="'salesOrderInfo'">
        <FilterTable
          ref="salesOrderInfo"
          columnsRef="salesOrderInfolsw"
          height="300"
          :isSelectColumn="false"
          :params="retailParams"
          :fetchapi="retailApi"
          :dataSource="salesOrderInfoList"
          :datakey="'records'"
          :columns="salesOrderInfoColumns"
          :onSyncTableData="handleSyncTableData"
          :onColumnsChange="columns => (this.salesOrderInfoColumns = columns)"
          v-if="activeTab == 'salesOrderInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="联系人信息" :name="'contactsInfo'">
        <FilterTable
          ref="contactsInfo"
          columnsRef="contactsInfolsw"
          height="300"
          :isSelectColumn="false"
          :dataSource="contactsInfoList"
          :columns="contactsInfoColumns"
          :fetchapi="contactsInfoFetchapi"
          :params="contactsInfoFetchParams"
          :datakey="'rows'"
          :isPagination="false"
          :isExportExcel="true"
          exportFileName="联系人信息.xlsx"
          :onColumnsChange="columns => (this.contactsInfoColumns = columns)"
          v-if="activeTab == 'contactsInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="维修历史信息" :name="'roHistoryInfo'">
        <FilterTable
          ref="roHistoryInfo"
          columnsRef="roHistoryInfolsw"
          selectionType="single"
          height="300"
          :isSelectColumn="false"
          :dataSource="roHistoryInfoList"
          :columns="roHistoryInfoColumns"
          :fetchapi="roHistoryInfoFetchapi"
          :params="roHistoryInfoFetchParams"
          :isExportExcel="true"
          :onSyncTableData="afterSyncTableData"
          :datakey="'rows'"
          exportFileName="维修历史信息.xlsx"
          :onColumnsChange="columns => (this.roHistoryInfoColumns = columns)"
          v-if="activeTab == 'roHistoryInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="索赔历史" :name="'claimHistory'">
        <FilterTable
          ref="claimHistory"
          columnsRef="claimHistorylsw"
          height="300"
          :isSelectColumn="false"
          :datakey="'records'"
          :dataSource="claimHistoryList"
          :columns="claimHistoryColumns"
          :fetchapi="claimHistoryFetchapi"
          :params="claimHistoryFetchParams"
          :onColumnsChange="columns => (this.claimHistoryColumns = columns)"
          v-if="activeTab == 'claimHistory'"
        >
          <template slot="controls">
            <AjaxButton size="small" type="primary" icon="el-icon-download" :click="claimHistoryExportData">导出</AjaxButton>
          </template>
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="活动参与情况" :name="'activityInfo'" v-if="false">
        <FilterTable
          ref="activityInfo"
          columnsRef="activityInfolsw"
          height="300"
          :isSelectColumn="false"
          :dataSource="activityInfoList"
          :columns="activityInfoColumns"
          :onColumnsChange="columns => (this.activityInfoColumns = columns)"
          v-if="activeTab == 'activityInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="救援信息" :name="'rescueInfo'">
        <FilterTable
          ref="rescueInfo"
          columnsRef="rescueInfolsw"
          height="300"
          :isSelectColumn="false"
          :datakey="'rows'"
          :dataSource="rescueInfoList"
          :columns="rescueInfoColumns"
          :fetchapi="rescueInfoFetchapi"
          :params="rescueInfoFetchParams"
          :isExportExcel="true"
          exportFileName="救援信息.xlsx"
          :onColumnsChange="columns => (this.rescueInfoColumns = columns)"
          v-if="activeTab == 'rescueInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="投诉信息" :name="'complaintInfo'">
        <FilterTable
          ref="complaintInfo"
          columnsRef="complaintInfolsw"
          height="300"
          :isSelectColumn="false"
          :dataSource="complaintInfoList"
          :columns="complaintInfoColumns"
          :onColumnsChange="columns => (this.complaintInfoColumns = columns)"
          v-if="activeTab == 'complaintInfo'"
        >
        </FilterTable>
      </el-tab-pane>
      <el-tab-pane label="会员信息" :name="'memberInfo'">
        <FormPanel ref="memberFormPanel" :list="memberFormList" :cols="3" :labelWidth="130" :formType="type" :isSubmitBtn="false" v-if="activeTab == 'memberInfo'" />
      </el-tab-pane>
    </el-tabs>
    <!-- 车辆明细 -->
    <BaseDialog :visible.sync="vehicleActions.visible" :title="vehicleActions.title" width="90%" destroyOnClose :containerStyle="{ height: '100%', overflow: 'auto' }">
      <vehicleDetail :type.sync="vehicleActions.type" :formData="this.resData" @close="closeHandler('vehicleInfo')" />
    </BaseDialog>
    <!-- OEM维修历史详情 -->
    <BaseDialog :visible.sync="roHistoryActions.visible" :title="roHistoryActions.title" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <oemOrderDetail :repairTypeDict="repairTypeDict" :sfqfDict="sfqfDict" :orderInfo="selectedOEMHistoryOrder" @close="closeHandler('roHistoryInfo')" />
    </BaseDialog>
    <!-- 救援单明细 -->
    <Drawer :visible.sync="rescueActions.visible" :title="rescueActions.title" width="90%" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <rescueOrderQueryPanel :formData="this.resData" @close="closeHandler('rescueInfo')" />
    </Drawer>
    <!-- 索赔明细 -->
    <Drawer
      :visible.sync="claimHistoryActions.visible"
      :title="claimHistoryActions.title"
      width="90%"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <claimDetails :formData="this.resData" @close="closeHandler('claimHistory')" />
    </Drawer>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关闭</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile, arrayObjDeWeight } from '@/utils/index';
import { notifyAction, findTableItem, findFormItem } from '@/utils';
import { getAllUser, getNameByIds } from '@/api/customerRepair/afterSaleVisit/resultEntry';
import { getWxlxSelect, getSfqfSelect } from '@/api/repair/repairReception/customer';
import { getRegion, getVehicleInfo, queryOEMRepairHistory, queryClaimHistory, exportClaimLogByExample, queryLinkInfoByOwnerNo } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getDearlerListByTranslate } from '@/api/customerRepair/vehicleOwnerManagement/vehicleChange';
import { getRescueList } from '@/api/customerRepair/rescueManagement/rescueOrder';
import { getPotentialInfo } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getRetailInfoForAfterSale } from '@/api/customerRepair/vehicleOwnerManagement/vehicleChange';
import { getUserId, getOwnerCode } from '@/assets/js/auth';
import { byAllInfo, dealerInfoByAllInfo } from '@/api/part/allocation';
import { getAppId } from '@/assets/js/auth';
import vehicleDetail from './vehicleDetail';
import claimDetails from './claimDetail';
import oemOrderDetail from '@/pages/repair/repairReception/customer/repairHistory/oemOrderDetail';
import rescueOrderQueryPanel from '@/pages/customerRepair/rescueManagement/rescueOrderQuery/rescueOrderQueryPanel';

export default {
  name: 'ownerQueryOEM',
  components: {
    vehicleDetail,
    oemOrderDetail,
    claimDetails,
    rescueOrderQueryPanel
  },
  mixins: [dictionary],
  props: {
    type: {
      type: String
    },
    formData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.selectedData = null;
    this.resData = null;
    this.repairTypeDict = []; // 维修类型字典
    this.sfqfDict = []; // 收费区分字典
    this.selectedOEMHistoryOrder = {}; // 选中查看的OEM工单
    return {
      activeTab: 'vehicleInfo',
      formList: this.createFromList(),
      vehicleInfoColumns: this.createTableColumnsvehicleInfo(),
      introducerInfoColumns: this.createTableColumnsintroducerInfo(),
      clueInfoColumns: this.createTableColumnsclueInfo(),
      salesOrderInfoColumns: this.createTableColumnssalesOrderInfo(),
      contactsInfoColumns: this.createTableColumnscontactsInfo(),
      roHistoryInfoColumns: this.createTableColumnsroHistoryInfo(),
      claimHistoryColumns: this.createTableColumnsclaimHistory(),
      activityInfoColumns: this.createTableColumnsactivityInfo(),
      rescueInfoColumns: this.createTableColumnsrescueInfo(),
      complaintInfoColumns: this.createTableColumnscomplaintInfo(),
      memberFormList: this.createMemberFromList(),
      userIds: '',
      vehicleInfoFetchapi: getVehicleInfo,
      contactsInfoFetchapi: queryLinkInfoByOwnerNo,
      claimHistoryFetchapi: queryClaimHistory,
      roHistoryInfoFetchapi: queryOEMRepairHistory,
      rescueInfoFetchapi: getRescueList,
      clueApi: getPotentialInfo,
      retailApi: getRetailInfoForAfterSale,

      vehicleInfoFetchParams: { xhrAbort: true, ownerCode: '', ownerNo: '', type: 'OEM' },
      contactsInfoFetchParams: { xhrAbort: true, ownerCode: '', ownerNo: '', type: 'OEM' },
      claimHistoryFetchParams: { xhrAbort: true, ownerCode: '', ownerNo: '' },
      roHistoryInfoFetchParams: { xhrAbort: true, ownerCode: '', ownerNo: '', type: 'OEM' },
      rescueInfoFetchParams: { xhrAbort: true, ownerCode: '', ownerNo: '', type: 'OEM' },
      retailParams: { mobile: this.formData.mobile },
      clueParams: { mobile: this.formData.mobile, ownerCode: this.formData.dealerCode, userId: getUserId() },

      vehicleActions: { visible: false, title: '', type: 'show' },
      claimHistoryActions: { visible: false, title: '', type: 'show' },
      roHistoryActions: { visible: false, title: '', type: 'show' },
      rescueActions: { visible: false, title: '', type: 'show' },
      syncTableData: [],
      syncTableDataAfter: [],
      vehicleInfoList: [], // 车辆信息集合
      introducerInfoList: [], // 介绍人信息集合
      clueInfoList: [], // 线索信息集合
      salesOrderInfoList: [], // 销售订单信息集合
      contactsInfoList: [], // 联系人信息集合
      roHistoryInfoList: [], // 维修历史信息集合
      claimHistoryList: [], // 索赔历史集合
      activityInfoList: [], // 活动参与情况集合
      rescueInfoList: [], // 救援信息集合
      complaintInfoList: [] // 投诉信息集合
    };
  },
  mounted() {
    if (this.formData.OWNER_CODE) {
      this.vehicleInfoFetchParams.ownerCode = this.formData.OWNER_CODE;
      this.vehicleInfoFetchParams.ownerNo = this.formData.ownerNo;
      this.vehicleInfoFetchParams.xhrAbort = false;

      this.contactsInfoFetchParams.ownerCode = this.formData.OWNER_CODE;
      this.contactsInfoFetchParams.linkOwnerNo = this.formData.ownerNo;
      this.contactsInfoFetchParams.xhrAbort = false;

      this.claimHistoryFetchParams.ownerCode = this.formData.OWNER_CODE;
      this.claimHistoryFetchParams.customerId = this.formData.ownerNo;
      this.claimHistoryFetchParams.xhrAbort = false;

      this.roHistoryInfoFetchParams.ownerCode = this.formData.OWNER_CODE;
      this.roHistoryInfoFetchParams.ownerNo = this.formData.ownerNo;
      this.roHistoryInfoFetchParams.xhrAbort = false;

      this.rescueInfoFetchParams.ownerCode = this.formData.OWNER_CODE;
      this.rescueInfoFetchParams.ownerNo = this.formData.ownerNo;
      this.rescueInfoFetchParams.xhrAbort = false;

      this.clueParams.mobile = this.formData.mobile;

      this.retailParams.mobile = this.formData.mobile;
      this.retailParams.vin = this.formData.vin;
    }
    // 字典值查询
    this.initDictCode();
    // 车主爱好字典值转换
    this.formList.forEach(x => {
      if (x.fieldName === 'hobby' && this.formData.hobby) {
        if (this.formData.hobby != null) {
          let hobby = this.formData.hobby.split(',');
          hobby = hobby.map(Number);
          x.initialValue = hobby;
        } else {
          x.initialValue = [];
        }
      }
    });
  },
  methods: {
    createFromList() {
      return [
        {
          type: 'INPUT',
          label: '创建经销商代码',
          fieldName: 'OWNER_CODE',
          initialValue: this.formData.OWNER_CODE,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '创建经销商名称',
          fieldName: 'dealerName',
          initialValue: this.formData.dealerName,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '客户姓名',
          fieldName: 'ownerName',
          initialValue: this.formData.ownerName,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '客户类型',
          fieldName: 'ownerProperty',
          initialValue: this.formData.ownerProperty,
          itemList: this.createDictList(8011),
          disabled: true
        },
        {
          type: 'DATE',
          label: '生日',
          fieldName: 'birthday',
          format: 'yyyy-MM-dd',
          initialValue: this.formData.birthday,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '客户手机',
          fieldName: 'mobile',
          initialValue: this.formData.mobile,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '客户电话',
          fieldName: 'phone',
          initialValue: this.formData.phone,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '证件类型',
          fieldName: 'ctCode',
          initialValue: this.formData.ctCode,
          itemList: this.createDictList('8013'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '证件号码',
          fieldName: 'certificateNo',
          initialValue: this.formData.certificateNo,
          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '微信号',
        //   fieldName: 'a1',
        //   initialValue: '',
        //   disabled: true
        // },
        {
          type: 'SELECT',
          label: '所在省份',
          fieldName: 'province',
          itemList: [],
          initialValue: this.formData.province,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '城市',
          fieldName: 'city',
          itemList: [],
          initialValue: this.formData.city,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '区县',
          fieldName: 'district',
          itemList: [],
          initialValue: this.formData.district,
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '居住地址',
          fieldName: 'address',
          rows: 2,
          selfCols: 3, // 元素占据几行
          initialValue: this.formData.address,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'zipCode',
          initialValue: this.formData.zipCode,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '单位性质',
          fieldName: 'industryFirst',
          itemList: this.createDictList('8251'),
          initialValue: this.formData.industryFirst,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '行业类型',
          fieldName: 'industrySecond',
          itemList: this.createDictList('8252'),
          initialValue: this.formData.industrySecond,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '职业',
          fieldName: 'vocationType',
          itemList: this.createDictList(8022),
          initialValue: this.formData.vocationType,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '职称',
          fieldName: 'position',
          itemList: this.createDictList(8023),
          initialValue: this.formData.position,
          disabled: true
          // rules: [{ required: true, message: '请选择行业类型', trigger: 'change' }]
        },
        // {
        //   type: 'SELECT',
        //   label: '学历',
        //   fieldName: 'a2',
        //   itemList: [],
        //   initialValue: '',
        //   disabled: true
        // },
        {
          type: 'SELECT',
          label: '婚姻状态',
          fieldName: 'ownerMarriage',
          itemList: this.createDictList('8018'),
          initialValue: this.formData.ownerMarriage,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '喜欢联系方式',
          fieldName: 'bestConcatType',
          itemList: this.createDictList('9123'),
          initialValue: this.formData.bestConcatType,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '年家庭收入',
          fieldName: 'familyIncome',
          itemList: this.createDictList(1290),
          initialValue: this.formData.familyIncome,
          disabled: true
        },
        {
          type: 'SELECT',
          label: '子女状况',
          fieldName: 'isChlidren',
          itemList: this.createDictList(1004),
          initialValue: this.formData.isChlidren,
          disabled: true
        },
        {
          type: 'MULTIPLE_SELECT',
          label: '爱好',
          fieldName: 'hobby',
          itemList: this.createDictList('8020'),
          disabled: true
        }
      ];
    },
    // 车辆信息table
    createTableColumnsvehicleInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 70,
          render: props => {
            return (
              <div style="text-align:center">
                <el-button size="mini" type="text" onClick={() => this.openHandler('vehicleInfo', props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: '发动机号',
          dataIndex: 'engineNo',
          showOverflowTooltip: true
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          width: 150,
          showOverflowTooltip: true
        },
        {
          title: '与车主关系',
          dataIndex: 'relationship',
          width: 150,
          showOverflowTooltip: true,
          dictItems: this.createDictList(8127)
        },
        {
          title: '建档日期',
          dataIndex: 'createdAt',
          width: 150,
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '是否激活',
          dataIndex: 'isActivaton',
          width: 150,
          showOverflowTooltip: true,
          dictItems: this.createDictList(1004)
        }
      ];
    },
    // 介绍人信息table
    createTableColumnsintroducerInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '介绍人姓名',
          dataIndex: 'a1',
          showOverflowTooltip: true
        },
        {
          title: '介绍人电话',
          dataIndex: 'a2',
          showOverflowTooltip: true
        },
        {
          title: '介绍人性质',
          dataIndex: 'a3',
          showOverflowTooltip: true
        },
        {
          title: '介绍人车牌号',
          dataIndex: 'a4',
          showOverflowTooltip: true
        },
        {
          title: '介绍人车辆VIN',
          dataIndex: 'a5',
          showOverflowTooltip: true
        }
      ];
    },
    //线索信息table
    createTableColumnsclueInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '跟进时间',
          dataIndex: 'trackAt',
          showOverflowTooltip: true
        },

        {
          title: '跟进前级别',
          dataIndex: 'contactBeforeLevel',
          showOverFlowTip: true,
          render: props => {
            return <span>{this.createDictText(props.row.contactBeforeLevel, 1519)}</span>;
          }
        },
        {
          title: '跟进后级别',
          dataIndex: 'factIntentLevel',
          showOverFlowTip: true,
          render: props => {
            return <span>{this.createDictText(props.row.factIntentLevel, 1519)}</span>;
          }
        },

        {
          title: '销售顾问',
          dataIndex: 'consultant',
          dictItems: [],
          showOverflowTooltip: true
        },

        {
          title: '意向车型',
          dataIndex: 'inteCarType',
          showOverflowTooltip: true
        },

        {
          title: '颜色',
          dataIndex: 'inteColour',
          showOverflowTooltip: true
        },

        {
          title: '跟进详情',
          dataIndex: 'taskName',
          showOverflowTooltip: true
        }
      ];
    },
    //订单销售信息table
    createTableColumnssalesOrderInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          // onChange: this.changeOwnerCode(props),
          showOverflowTooltip: true
        },
        {
          title: '经销商名称',
          dataIndex: 'a2',
          dictItems: this.translateDealer(),
          showOverflowTooltip: true
        },
        {
          title: '销售单号',
          dataIndex: 'orderNo',
          showOverflowTooltip: true
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          showOverflowTooltip: true
        },
        {
          title: '销售时间',
          dataIndex: 'saleDate',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '支付方式',
          dataIndex: 'payType',
          dictItems: this.createDictList('6015'),
          showOverflowTooltip: true
        },
        {
          title: '发票号',
          dataIndex: 'invoiceNo',
          showOverflowTooltip: true
        },
        {
          title: '开票时间',
          dataIndex: 'invoiceDate',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        // {
        //   title: '是否三包',
        //   dataIndex: 'a9',
        //   showOverflowTooltip: true
        // },
        {
          title: '车辆用途',
          dataIndex: 'buyPurpose',
          dictItems: this.createDictList('1511'),
          showOverflowTooltip: true
        }
      ];
    },
    //联系人信息table
    createTableColumnscontactsInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '联系人姓名',
          dataIndex: 'ownerName',
          showOverflowTooltip: true
        },
        {
          title: '客户性别',
          dataIndex: 'gender',
          dictItems: this.createDictList(8012),
          showOverFlowTip: true
        },
        {
          title: '联系人与车主关系',
          dataIndex: 'relationship',
          dictItems: this.createDictList(8127),
          showOverFlowTip: true
        },
        {
          title: '联系人电话',
          dataIndex: 'phone',
          showOverflowTooltip: true
        },
        {
          title: '联系人手机',
          dataIndex: 'mobile',
          showOverflowTooltip: true
        },
        {
          title: '省份',
          dataIndex: 'province',
          showOverflowTooltip: true
        },
        {
          title: '城市',
          dataIndex: 'city',
          showOverflowTooltip: true
        },
        {
          title: '区县',
          dataIndex: 'district',
          showOverflowTooltip: true
        },
        {
          title: '地址',
          dataIndex: 'address',
          showOverflowTooltip: true
        }
      ];
    },
    //维修历史信息table
    createTableColumnsroHistoryInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 70,
          render: props => {
            return (
              <div style="text-align:center">
                <el-button size="mini" type="text" onClick={() => this.openHandler('roHistoryInfo', props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          showOverflowTooltip: true
        },
        {
          title: '维修经销商代码',
          dataIndex: 'OWNER_CODE',
          showOverflowTooltip: true
        },
        {
          title: '维修经销商名称',
          dataIndex: 'dealerName',
          dictItems: [],
          showOverflowTooltip: true
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          showOverflowTooltip: true
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          showOverflowTooltip: true
        },
        // {
        //   title: '工单类型',
        //   dataIndex: 'a0',
        //   dictItems: [],
        //   showOverflowTooltip: true
        // },
        // {
        //   title: '活动代码',
        //   dataIndex: 'a2',
        //   showOverflowTooltip: true
        // },
        // {
        //   title: '活动名称',
        //   dataIndex: 'a3',
        //   showOverflowTooltip: true
        // },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          dictItems: [],
          showOverflowTooltip: true
        },
        {
          title: '进厂里程',
          dataIndex: 'IN_MILEAGE',
          showOverflowTooltip: true
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '维修日期',
          dataIndex: 'REPAIR_BEGIN_DATE',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '结算日期',
          dataIndex: 'BALANCE_TIME',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '服务工程师',
          dataIndex: 'SERVICE_ADVISOR',
          showOverflowTooltip: true
        },
        {
          title: '送修人姓名',
          dataIndex: 'DELIVERER',
          showOverflowTooltip: true
        },
        {
          title: '送修人电话',
          dataIndex: 'DELIVERER_MOBILE',
          showOverflowTooltip: true
        }
        // {
        //   title: '送修人地址',
        //   dataIndex: 'a8',
        //   showOverflowTooltip: true
        // }
      ];
    },
    //索赔历史table
    createTableColumnsclaimHistory() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 70,
          render: props => {
            return (
              <div style="text-align:center">
                <el-button size="mini" type="text" onClick={() => this.openHandler('claimHistory', props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '索赔单号',
          dataIndex: 'claimNo',
          showOverflowTooltip: true
        },
        {
          title: '工单号',
          dataIndex: 'roNo',
          showOverflowTooltip: true
        },
        {
          title: '维修经销商代码',
          dataIndex: 'ownerCode',
          showOverflowTooltip: true
        },
        {
          title: '维修经销商名称',
          dataIndex: 'ownerName',
          showOverflowTooltip: true
        },
        {
          title: '索赔类型',
          dataIndex: 'cmsClaimTypeStr',
          showOverflowTooltip: true
        },
        {
          title: '质量报告号',
          dataIndex: 'reportNo',
          showOverflowTooltip: true
        },
        {
          title: '索赔审核日期',
          dataIndex: 'checkAt',
          dateFormat: 'yyyy-MM-dd',
          showOverflowTooltip: true
        }
      ];
    },
    //活动参与情况table
    createTableColumnsactivityInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'a1',
          showOverflowTooltip: true
        },
        {
          title: '维修经销商代码',
          dataIndex: 'a2',
          showOverflowTooltip: true
        },
        {
          title: '维修经销商名称',
          dataIndex: 'a3',
          showOverflowTooltip: true
        },
        {
          title: '维修类型',
          dataIndex: 'a4',
          showOverflowTooltip: true
        },
        {
          title: '开单时间',
          dataIndex: 'a5',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '完成时间',
          dataIndex: 'a6',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '优惠券码',
          dataIndex: 'a7',
          showOverflowTooltip: true
        }
      ];
    },
    //救援信息table
    createTableColumnsrescueInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 70,
          render: props => {
            return (
              <div style="text-align:center">
                <el-button size="mini" type="text" onClick={() => this.openHandler('rescueInfo', props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '救援单工号',
          dataIndex: 'rescueNo',
          showOverflowTooltip: true
        },
        {
          title: '救援经销商代码',
          dataIndex: 'OWNER_CODE',
          showOverflowTooltip: true
        },

        {
          title: '救援经销商名称',
          dataIndex: 'dealerName',
          dictItems: [],
          showOverflowTooltip: true
        },
        {
          title: '来电人姓名',
          dataIndex: 'ownerName',
          showOverflowTooltip: true
        },
        {
          title: '来电人电话',
          dataIndex: 'ownerMobile',
          showOverflowTooltip: true
        },
        {
          title: '救援地址',
          dataIndex: 'address',
          showOverflowTooltip: true
        },
        {
          title: '服务类型',
          dataIndex: 'rescueModeThree',
          dictItems: this.createDictList(1222),
          showOverflowTooltip: true
        },
        {
          title: '救援时间',
          dataIndex: 'appointmentDate',
          format: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '派单方式',
          dataIndex: 'dataSources',
          dictItems: this.createDictList(1045),
          showOverflowTooltip: true
        }
      ];
    },
    //投诉信息table
    createTableColumnscomplaintInfo() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'a1',
          showOverflowTooltip: true
        },
        {
          title: '投诉经销商代码',
          dataIndex: 'a2',
          showOverflowTooltip: true
        },

        {
          title: '投诉经销商名称',
          dataIndex: 'a3',
          showOverflowTooltip: true
        },

        {
          title: '车主姓名',
          dataIndex: 'a4',
          showOverflowTooltip: true
        },

        {
          title: '车主电话',
          dataIndex: 'a5',
          showOverflowTooltip: true
        },

        {
          title: '地址',
          dataIndex: 'a6',
          showOverflowTooltip: true
        },

        {
          title: '抱怨类型',
          dataIndex: 'a7',
          showOverflowTooltip: true
        },

        {
          title: '派单方式',
          dataIndex: 'a8',
          showOverflowTooltip: true
        },

        {
          title: '处理方式',
          dataIndex: 'a9',
          showOverflowTooltip: true
        },

        {
          title: '处理状态',
          dataIndex: 'a10',
          showOverflowTooltip: true
        },

        {
          title: '仲裁处理结果',
          dataIndex: 'a11',
          showOverflowTooltip: true
        }
      ];
    },
    // 会员信息form表单
    createMemberFromList() {
      return [
        {
          type: 'INPUT',
          label: '会员号ID',
          fieldName: 'a1',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '会员姓名',
          fieldName: 'a2',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '会员电话',
          fieldName: 'a3',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '会员等级',
          fieldName: 'a4',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '会员创建时间',
          fieldName: 'a5',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '会员有效期',
          fieldName: 'a6',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '会员积分',
          fieldName: 'a7',
          disabled: true,
          initialValue: ''
        }
      ];
    },

    // 打开弹窗
    openHandler(type, val) {
      if (type === 'vehicleInfo') {
        // 打开车辆明细弹窗
        this.vehicleActions = { visible: true, title: '车辆明细', type: 'show' };
        this.resData = val;
      } else if (type === 'roHistoryInfo') {
        // 打开维修历史明细弹窗
        this.roHistoryActions = { visible: true, title: '工单信息', type: 'show' };
        this.selectedOEMHistoryOrder = val;
      } else if (type === 'claimHistory') {
        // 打开索赔历史明细弹窗
        this.claimHistoryActions = { visible: true, title: '索赔信息', type: 'show' };
        this.resData = val;
      } else if (type === 'rescueInfo') {
        // 打开救援明细弹窗
        this.rescueActions = { visible: true, title: '救援单明细', type: 'show' };
        this.resData = val;
      }
    },
    // 关闭弹窗
    closeHandler(type) {
      if (type === 'vehicleInfo') {
        this.vehicleActions = { visible: false, title: '车辆明细', type: 'show' };
      } else if (type === 'roHistoryInfo') {
        this.roHistoryActions = { visible: false, title: '工单信息', type: 'show' };
      } else if (type === 'rescueInfo') {
        this.rescueActions = { visible: false, title: '救援单明细', type: 'show' };
      } else if (type === 'claimHistory') {
        this.claimHistoryActions = { visible: false, title: '索赔信息', type: 'show' };
      }
    },
    async afterSyncTableData(val) {
      this.syncTableDataAfter = val;
      let userArr = this.syncTableDataAfter.map(item => item.SERVICE_ADVISOR);
      let userStr = [...new Set(userArr)].join(',');
      this.userIds = userStr;
      let res = await getNameByIds({ userIds: this.userIds });
      if (res.resultCode == 200) {
        this.roHistoryInfoColumns.find(y => y.dataIndex == 'SERVICE_ADVISOR').dictItems = res.data.map(x => ({ text: x.employeeName, value: x.employeeId }));
      }
    },
    // 查询字典值
    initDictCode() {
      // 获取省市区
      this.getRegion();
      // 获取全部人员
      this.getAllUser();
      // 获取维修类型
      this.queryRepairTypeDict();
      // 查询经销商列表
      this.getDearlerListByTranslate();
      // 获取收费区分
      this.querySfqfDict();
    },
    // 获取省市区
    async getRegion() {
      const allRegion = await getRegion();
      if (allRegion.resultCode === 200) {
        if (allRegion.errMsg) {
          notifyAction(allRegion.errMsg, 'error');
        } else {
          let regionList = allRegion.data.map(x => ({ value: x.regionId, text: x.regionName }));
          let targetFormItems = [findFormItem(this.formList, 'province'), findFormItem(this.formList, 'city'), findFormItem(this.formList, 'district')];
          let targetTableItems = [findTableItem(this.contactsInfoColumns, 'province'), findTableItem(this.contactsInfoColumns, 'city'), findTableItem(this.contactsInfoColumns, 'district')];

          targetFormItems.forEach(item => {
            item.itemList = regionList;
          });
          targetTableItems.forEach(item => {
            item.dictItems = regionList;
          });
        }
      }
    },
    // 所有用户
    async getAllUser() {
      const res = await getAllUser();
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'error');
        } else {
          let tableList = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
          let targetTableItems = [findTableItem(this.clueInfoColumns, 'a1')];
          targetTableItems.forEach(item => {
            item.dictItems = tableList;
          });
        }
      }
    },
    // 获取维修类型
    async queryRepairTypeDict() {
      let res = await getWxlxSelect();
      if (res.resultCode == 200) {
        let repairTypeDict = res.data.map(item => ({ text: item.REPAIR_TYPE_NAME, value: item.REPAIR_TYPE_CODE + '' }));
        this.repairTypeDict = repairTypeDict;
        let targetTableItems = [findTableItem(this.roHistoryInfoColumns, 'REPAIR_TYPE_CODE')];
        targetTableItems.forEach(item => {
          item.dictItems = item.filterItems = repairTypeDict;
        });
      }
    },
    // 查询全部经销商列表
    async getDearlerListByTranslate() {
      const res = await getDearlerListByTranslate();
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'error');
        } else {
          let dealerList = res.data.map(item => ({ text: item.dealerName, value: item.dealerCode + '' }));
          let targetTableItems = [findTableItem(this.roHistoryInfoColumns, 'dealerName'), findTableItem(this.rescueInfoColumns, 'dealerName')];
          targetTableItems.forEach(item => {
            item.dictItems = dealerList;
          });
        }
      }
    },
    // 获取收费区分(维修历史明细中需要)
    async querySfqfDict() {
      let res = await getSfqfSelect();
      if (res.resultCode == 200) {
        this.sfqfDict = res.data.map(item => ({ text: item.CHARGE_PARTITION_NAME, value: item.CHARGE_PARTITION_CODE }));
      }
    },
    handleSyncTableData(val) {
      this.syncTableData = val;
      val.forEach(x => {
        x.a2 = x.ownerCode;
      });
    },
    handleSyncTableDataVehicle(val) {
      if (getAppId() == 'arcfox') {
        this.vehicleInfoColumns.find(x => x.dataIndex == 'engineNo').title = '电机号';
        val.forEach(x => {
          x.engineNo = x.motorNo1 ? x.motorNo1 : x.motorNo2;
        });
      }
    },
    async handleSyncTableDataClueInfo(val) {
      let userIds = val.map(x => x.consultant).join(',');
      let res = await getNameByIds({ userIds: userIds });
      if (res.resultCode == 200) {
        this.clueInfoColumns.find(x => x.dataIndex == 'consultant').dictItems = res.data.map(x => ({ text: x.employeeName, value: x.employeeId }));
      }
    },
    //翻译经销商名称
    async translateDealer() {
      let res = await dealerInfoByAllInfo();
      console.log(res, 'dealerInfoByAllInfo');
      let data = arrayObjDeWeight(res.data, 'dealerCode');
      this.salesOrderInfoColumns.find(item => item.dataIndex == 'a2').dictItems = data.map(x => ({ text: x.dealerName, value: x.dealerCode }));
    },
    // 索赔历史导出
    async claimHistoryExportData() {
      await exportClaimLogByExample(this.claimHistoryFetchParams).then(res => {
        if (res.status !== 'failure') {
          exportExcelFile(res.data, '索赔历史导出');
        } else {
          notifyAction('导出失败', 'error');
        }
      });
    },
    closeDialog() {
      this.$emit('close', false);
    }
  }
};
</script>
<style lang="less" scoped></style>
